﻿param($myservicename, $instancen, $location1, $location2, $storageaccount, $size, $template)

# fix the python "argument with spaces" bug
$location = $location1+" "+$location2

# My subscription credentials
Import-AzurePublishSettingsFile 'your credentials file.publishsettings'
# Set the default storage account
#$mystorage=Get-AzureStorageAccount -StorageAccountName $storageaccount
Get-AzureSubscription | Set-AzureSubscription -CurrentStorageAccount $storageaccount

# Admin user name and password. Note that administrator is disabled
$mypassword = "your password"
$myadmin = "your user name, not admin"

# Start deployment, all vms in 1 service

$VM1 = New-AzureVMConfig -ImageName $template -Name ($myservicename+"1") -InstanceSize $size -hostcaching ReadWrite -DiskLabel "System"
$VM1 = Add-AzureProvisioningConfig -Windows -VM $VM1 -Password $mypassword -AdminUsername $myadmin

New-AzureVM -VMs $VM1 -servicename $myservicename -Location $location 

$VM2=0..($instancen-2)
for ($index=0; $index -le $instancen-2; $index++)
{
    $VM2[$index] = New-AzureVMConfig -ImageName $template -Name ($myservicename+($index+2)) -InstanceSize $size -hostcaching ReadWrite -DiskLabel "System"
    $VM2[$index] = Add-AzureProvisioningConfig -Windows -VM $VM2[$index] -Password $mypassword -AdminUsername $myadmin
   
    #New-AzureVM -VMs $VM1 -servicename $myservicename 
}
New-AzureVM -VMs $VM2 -ServiceName $myservicename
$machines=Get-AzureVM -ServiceName $myservicename
exit $machines.count

